# pylint: disable=C0103
"""user verified column

Revision ID: 76fd6db54f65
Revises: 245d4295bbd6
Create Date: 2024-11-18 09:57:42.103381

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import update, Integer, and_, Boolean
from sqlalchemy.orm import Session
from sqlalchemy.sql import table, column

# revision identifiers, used by Alembic.
revision = '76fd6db54f65'
down_revision = '245d4295bbd6'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('user', sa.Column('verified', Boolean(), nullable=False))
    user_table = table(
        'user',
        column('deleted_at', Integer()),
        column('verified', Boolean())
    )
    bind = op.get_bind()
    session = Session(bind=bind)
    try:
        upd_stmt = update(user_table).values(verified=True).where(and_(
            user_table.c.verified.is_(False),
            user_table.c.deleted_at == 0
        ))
        session.execute(upd_stmt)
        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('user', 'verified')
    # ### end Alembic commands ###
